package com.ssy.wireless.web.service;

import com.ssy.wireless.entity.Hotspot;
import com.ssy.wireless.entity.HotspotOnlineStat;
import com.ssy.wireless.entity.HotspotTrafficStat;
import com.ssy.wireless.entity.LastMonthStat;
import com.ssy.wireless.mapper.HotspotMapper;
import com.ssy.wireless.mapper.HotspotOnlineStatMapper;
import com.ssy.wireless.mapper.HotspotTrafficStatMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by cofey on 16/11/20.
 */
@Service
@Transactional(readOnly = true)
public class HotspotService {
    @Autowired
    private HotspotMapper hotspotMapper;

    @Autowired
    private HotspotTrafficStatMapper hotspotTrafficStatMapper;

    @Autowired
    private HotspotOnlineStatMapper hotspotOnlineStatMapper;

    public Hotspot findById(Long id) {
        return hotspotMapper.selectByPrimaryKey(id);
    }

    public List<Hotspot> find(Map<String, Object> params) {
        return hotspotMapper.select(params);
    }

    public List<HotspotTrafficStat> findTrafficStatistics(Map<String, Object> params) {
        return hotspotTrafficStatMapper.selectStatistics(params);
    }

    public List<HotspotOnlineStat> findOnlineStatistics(Map<String, Object> params) {
        return hotspotOnlineStatMapper.selectStatistics(params);
    }

    @Transactional
    public int update(Hotspot hotspot) {
        return hotspotMapper.updateByPrimaryKey(hotspot);
    }

    /**
     * 获取最早创建的热点时间
     *
     * @return
     */
    public Date selectTheFirstDate() {
        return hotspotMapper.selectTheFirstDate();
    }

    /**
     * 查询各类型热点数量
     *
     * @return
     */
    public int selectTypeCount(int type) {
        return hotspotMapper.selectTypeCount(type);
    }

    /**
     * 查询上月运行情况
     *
     * @return
     */
    public List<LastMonthStat> selectLastMonthStat() {
        return hotspotMapper.selectLastMonthStat();
    }
}
